package com.shiyi.shiyiaiagent.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.rag.preretrieval.query.expansion.MultiQueryExpander;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 基于内存的向量数据库配置
 */
@Configuration
public class LoveAppVectorStoreConfig {

  @Resource
  private LoveAppDocumentLoader loveAppDocumentLoader;

  @Resource MyKeywordEnricher myKeywordEnricher;

  @Bean
  VectorStore loveAppVectorStore(EmbeddingModel embeddingModel) {
    SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(embeddingModel).build();
    List<Document> documents = loveAppDocumentLoader.loadDocuments();
    List<Document> enrichDocuments = myKeywordEnricher.enrichDocument(documents);
    simpleVectorStore.add(enrichDocuments);
    return simpleVectorStore;
  }
}
